<template>
  <view>
    <customtop top_title="分销收益"></customtop>
    <view class="hlist" v-if="!data_list_loading">
      <view v-if="data_list.length > 0">
        <view class="items container">
          <view class="item" v-for="(item, index) in data_list" :key="index">
            <view class="info">
              <view class="txt">{{item.description}}</view>
              <view class="ident">+{{item.price}}</view>
            </view>
            <view class="date">{{item.created_at}}</view>
          </view>
        </view>
        <view class="uloadmore"><u-loadmore :status="loadmore_status" /></view>
      </view>
      <u-empty
        mode="data"
        icon="http://cdn.uviewui.com/uview/empty/data.png"
        text="近期暂无收益~"
        v-if="data_list.length == 0"
      >
      </u-empty>
    </view>
  </view>
</template>

<script>
import { request } from "@/utils/http.js"
import customtop from "@/components/customtop.vue"

export default {
  components: { customtop },

  data() {
    return {
      data_list: [],
      data_list_loading: true,
      loadmore_status: 'loadmore',
      loadmore_finished: false,
      params: {
        page_size: 15,
        page: 1,
      },
    }
  },

  onLoad: function() {
    uni.showLoading();
    this.getDistributionEarningsPaginate();
  },

  // 加载更多
  onReachBottom() {
    this.getMore();
  },

  // 下拉刷新
  onPullDownRefresh: function() {
    this.getInit();
  },

  methods: {
    getDistributionEarningsPaginate: function() {
      let params = this.params;
      request.post('/user/getDistributionEarningsPaginate', params).then(res => {
        uni.stopPullDownRefresh();
        uni.hideLoading();
        this.data_list_loading = false;

        // 返回数据为空
        if (res.data.total == 0) {
          this.data_list = [];
          return false;
        }

        // 组装数据
        if (res.data.current_page == 1) {
          this.data_list = res.data.data;
        } else {
          this.data_list = this.data_list.concat(res.data.data);
        }

        // 最后一页
        if (this.params.page == res.data.last_page) {
          this.loadmore_finished = true;
          this.loadmore_status = 'nomore';
          return false;
        }

        this.params.page = parseInt(res.data.current_page) + parseInt(1);
        this.loadmore_status = 'loadmore';
        this.loadmore_finished = false;
      })
    },

    // 初始化请求
    getInit: function() {
      uni.showLoading()
      this.params.page = 1;
      this.getDistributionEarningsPaginate();
    },

    // 加载更多
    getMore: function() {
      if (!this.loadmore_finished) {
        this.loadmore_status = 'loading';
        this.getDistributionEarningsPaginate();
      }
    },

    switchTab: function(url) {
      uni.switchTab({ url: url })
    },

    jumpPage: function(url) {
      uni.navigateTo({ url: url })
    }
  }
}
</script>

<style>
page {
  padding-bottom: 50rpx;
  background-color: #fff;
}

.hlist {
  margin-top: 30rpx;
}
.hlist .items {
  margin-bottom: 30rpx;
}
.hlist .items .item {
	border-bottom: 1px solid #f5f5f5;
  padding-bottom: 30rpx;
  margin-bottom: 30rpx;
}
.hlist .items .info {
	overflow: hidden;
}
.hlist .items .info .txt {
	float: left;
  max-width: 80%;
}
.hlist .items .info .ident {
	float: right;
	color: #61e7ce;
	font-weight: 600;
}
.hlist .items .item .date {
	font-size: 24rpx;
	color: #999;
	margin-top: 5px;
}
</style>
